- Increment/decrement operator

++x <=> x++ both increment x by 1

++x (prefix ++) higher priority than =, which in turn has higher priority than x++ (postfix)

Example#1: IncrementDemo.java

- There are 3 way to increment a variable by 1: 

Approach#1: x = x + 1;
Approach#2: x += 1; 
Approach#3: x++;


String x = "Hi";
x += " There";
System.out.println(x); // HiThere

x *= 1; <=> x = x * 1;
x /= 2; <=> x = x / 2;
x %= 3; <=> x = x % 3;

- Data conversion

a) Assignment: 

int dollars = 45;
double money = dollars;

int (32 bits) ---> double (64): widening conversion

double money = 45.6;
int dollars = money; // Compile-time error

Assignment operator does not support narrowing conversion

float value = 23.5; // Compile-time error

b) Promotion:

7 / 2.0 ---> 7.0 / 2.0 ---> 3.5

"Hi" + 5 ---> "Hi" + "5" ---> "Hi5"

c) A group of int values
1	4	6

int sum = 11;
int count = 3;

double average =  sum / (double) count; 

If division is performed first, average = (double) 3; // average = 3.0
If cast operator is evaluated first, average =  11.0 / 3; // average = 3.666...

Be careful!


double average = (double) (sum / count); // average = 3.0

int money = (int) 23.5;
System.out.println(money); // 23

- Scanner
Packages
java.util

Example#2: Echo.java


















